
package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.units;

/**
 * A simple class to represent a Gene. The gene has a string identifier and is equal to
 * another Gene if that string identifier is equal.
 * @author Jamie MacPherson
 */
public class Gene implements Comparable{

    // the gene ID
    private final String id;

    /**
     * @param id a unique identifier for the gene.
     */
    public Gene(String id) {
        this.id = id;
    }

    /**
     *
     * @return the unique identifier for the gene
     */
    public String getId() {
        return id;
    }

    /**
     * Though this class currently only contains the ID field,
     * only this field should be used to test equivalence.
     * @param obj the object to test for equality.
     * @return true if the object is equal to this gene, only
     * if the object is a gen with the same ID, false if not.
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Gene other = (Gene) obj;
        if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }

    /**
     * Generates a hash code based only on the gene identifier
     * @return
     */
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    
    /**
     * allows genes to be sorted in an order the same as
     * the natural ordering of their string identifiers.
     */
    public int compareTo(Object o) {
        Gene otherGene = null;
        int c = 0;
        try{
            otherGene = (Gene) o;
            c= this.getId().compareTo(otherGene.getId());
        } catch(ClassCastException e){
            e.printStackTrace();
        }
        return c;

    }

}
